package com.example.websocket;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * @author Huangyt
 * @version 1.0
 * @date 2020/9/20 10:18
 */
public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
        //获取HttpSession
        HttpSession httpSession = (HttpSession) request.getHttpSession();
        //将HttpSession存入ServerEndpointConfig中
        config.getUserProperties().put(HttpSession.class.getName(), httpSession);
    }
}